export const last7days = (() => {
  const end = new Date();
  const start = new Date();
  start.setTime(start.getTime() - (3600 * 1000 * 24 * 7));
  start.setTime(new Date(start.toLocaleDateString()).getTime()); // 当天0点
  return [start, end];
})();

export const options1 = {
  shortcuts: [
    {
      text: '最近7天',
      onClick(picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - (3600 * 1000 * 24 * 7));
        start.setTime(new Date(start.toLocaleDateString()).getTime()); // 当天0点
        picker.$emit('pick', [start, end]);
      },
    },
    {
      text: '最近30天',
      onClick(picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - (3600 * 1000 * 24 * 30));
        start.setTime(new Date(start.toLocaleDateString()).getTime()); // 当天0点
        picker.$emit('pick', [start, end]);
      },
    },
    {
      text: '最近90天',
      onClick(picker) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - (3600 * 1000 * 24 * 90));
        start.setTime(new Date(start.toLocaleDateString()).getTime()); // 当天0点
        picker.$emit('pick', [start, end]);
      },
    },
  ],
};

export const options2 = {};

export const ymd = (time) => {
  const curY = new Date().getFullYear();
  const y = time.getFullYear();
  const m = time.getMonth() + 1;
  const d = time.getDate();
  return y < curY ? `${y}-${m}-${d}` : `${m}-${d}`;
};

export const getEveryDay = (daterange) => {
  const start = new Date(daterange[0]); // 重新生成一遍，不然会导致横轴消失
  const end = new Date(daterange[1]);
  const xAxisDate = [];
  while (start.getTime() < end.getTime()) {
    xAxisDate.push(ymd(start));
    start.setTime(start.getTime() + (3600 * 1000 * 24)); // 加上一天
  }
  return xAxisDate;
};
